﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.MODEL.Frontier;
using MINERP.DAL;

namespace MINERP.BLL.Frontier
{
    public class PaperConfigRecordBLL
    {
        /// <summary>
        /// 获得纸型，纸宽设置记录
        /// </summary>
        /// <returns></returns>
        public List<PaperConfigRecordInfo> GetPaperConfigRecordList()
        {
            List<PaperConfigRecordInfo> list = new List<PaperConfigRecordInfo>();
            using (newSampleYPDBEntities enty = new newSampleYPDBEntities())
            {
                List<PaperConfigRecord> listPaperConfig = enty.PaperConfigRecord.OrderByDescending(p=>p.CreateTime).ToList();
                foreach (var item in listPaperConfig)
                {
                    PaperConfigRecordInfo pc = new PaperConfigRecordInfo();
                    pc.CreateTime = item.CreateTime;
                    pc.PaperConfigRecordId = item.PaperConfigRecordId;
                    pc.PaperTypeName = item.PaperTypeName;
                    //pc.PaperFaceName = item.PaperFaceName;
                    pc.PaperWidth = item.PaperWidth;
                    list.Add(pc);
                }
 
            }
            return list;
        }

        /// <summary>
        /// 添加纸设置记录
        /// </summary>
        /// <param name="paperTypeName"></param>
        /// <param name="paperWidth"></param>
        /// <returns></returns>
        public int AddPaperConfigRecord(string paperTypeName,double paperWidth)
        {
            int ret = 0;
            try
            {
                using (newSampleYPDBEntities enty = new newSampleYPDBEntities())
                {
                    PaperConfigRecord pcr = enty.PaperConfigRecord.FirstOrDefault(p => p.PaperTypeName == paperTypeName &&p.PaperWidth == paperWidth);
                    if (pcr == null)
                    {
                        PaperConfigRecord pRecord = new PaperConfigRecord();
                        pRecord.CreateTime = DateTime.Now;
                        pRecord.PaperTypeName = paperTypeName;
                        pRecord.PaperWidth = paperWidth;
                        enty.AddToPaperConfigRecord(pRecord);
                        enty.SaveChanges();
                    }
                }
            }
            catch
            {
                ret = -1;
            }
            return ret;
        }
    }
}
